package com.fjxd.order.web;

import com.fjxd.feign.clients.TicketStoreClient;
import com.fjxd.feign.clients.UserClient;
import com.fjxd.feign.pojo.Ticket;
import com.fjxd.order.pojo.Order;
import com.fjxd.order.pojo.OrderManyPeople;
import com.fjxd.order.pojo.vo.CreateOrderVo;
import com.fjxd.order.pojo.vo.OrderVo;
import com.fjxd.order.pojo.vo.TicketVo;
import com.fjxd.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fjxd.feign.result.ViewResult;

import java.util.List;

/**
 * @author csw
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    TicketStoreClient ticketStoreClient;
    @Autowired
    UserClient userClient;




    @PostMapping("/updateOrder")
    public ViewResult updateOrder(@RequestBody Order order) {
        Integer integer = orderService.updateOrder(order);
        return ViewResult.success(integer);
    }
    @GetMapping("/updateOrderStatusById/{id}/{status}")
    public boolean updateOrderStatusById(@PathVariable Integer id,@PathVariable Integer status)
    {
        return orderService.updateOrderStatusById(id,status);
    }


    @GetMapping("/getOrderByUserId/{id}")
    public List<Order> getOrderByUserId(@PathVariable Integer id){
        return orderService.getOrderByUserId(id);
    }



    /*
    * 一对多 一个订单可以有多名乘客
    * */
    @GetMapping("/getOrderManyPeople/{orderId}")
    public List<OrderVo> getOrderManyPeople(@PathVariable Integer orderId){
        return orderService.getOrderManyPeople(orderId);
    }
    @GetMapping("/getOrderManyTicket/{orderId}")
    public List<TicketVo> getOrderManyTicket(@PathVariable Integer orderId)
    {
        return orderService.getOrderManyTicket(orderId);
    }
    @GetMapping("/getOrderById/{orderId}")
    public List<Order> getOrderById(@PathVariable Integer orderId){
        return orderService.getOrderById(orderId);
    }

    @PostMapping("/createOrder")
    public Integer createOrder(@RequestBody CreateOrderVo createOrderVo){
        return orderService.createOrder(createOrderVo);
    }
    @DeleteMapping("/deleteOrderById/{id}")
    public boolean deleteOrderById(@PathVariable Integer id) {
        return orderService.delOrderById(id);
    }
    @PostMapping("/retreatTicket")
    public boolean retreatTicket(@RequestBody List<Integer> storeId,Integer count){

        return orderService.retreatTicket(storeId,count);
    }
}
